#ifndef CANDELABRODB_H
#define CANDELABRODB_H



#include <QString>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlRecord>
#include "ohlcvitem.h"
#include "ohlcvset.h"
#include <QMutex>
#include <QDate>

class CandelabroDB
{
public:
    CandelabroDB();

    //db config
    bool isDatabaseOpen();
    bool databaseExists();
    bool isDatabaseSetup();
    bool deleteDatabase();
    bool openDatabase();
    bool setUpDatabase();
    bool closeDatabase();
    bool connectionAlreadyExists();
    bool existsTableStocks();
    bool existsTableStockPrices();



    //stockprices
    bool existsPrice(QString stockName, uint unixdate);
    bool insertStockPrice(OHLCVItem item);
    bool insertStockPrice(OHLCVSet set);
    bool deleteSet(OHLCVSet set);
    OHLCVSet getStockPrices(QString stockName, QDate startDate, QDate endDate);


    //stocks
    bool insertStock(QString stockName, QString stockDescription = QString(""));
    QStringList getPricedStocksNames();
    QStringList getAllStocksNames();
    bool existsStock(QString stockName);
    int stockId(QString stockName);


    OHLCVSet selectAll(QString stockName);

private:

    QSqlDatabase connection;

    //config data
    QString sqlTableStockPrices;
    QString sqlTableStocks;
    QString sqlTableStockPriceExists;
    QString sqlTableStocksExists;
    QString sqlPragmaConfigsFK;
    QString connectionName;
    QString databaseDriver;
    QString databaseName;


};

#endif // CANDELABRODB_H
